package com.fowo.api.sys.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fowo.api.common.model.R;
import com.fowo.api.sys.entity.SysParam;
import com.fowo.api.sys.model.SysParamEditModel;
import com.fowo.api.sys.model.SysParamSearch;
import com.fowo.api.sys.service.SysParamService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Tag(name = "系统参数")
@RestController
@RequestMapping("/api/sys/param")
public class SysParamController {

    @Resource
    private SysParamService sysParamService;

    @GetMapping("page")
    @Operation(summary = "分页搜索")
    public R<Page<SysParam>> searchPage(SysParamSearch search) {
        return R.data(() -> sysParamService.searchPage(search));
    }

    @GetMapping
    @Operation(summary = "搜索")
    public R<List<SysParam>> search(SysParamSearch search) {
        return R.data(() -> sysParamService.search(search));
    }

    @GetMapping("{id}")
    @Operation(summary = "获取")
    public R<SysParam> getById(@PathVariable Long id) {
        return R.data(() -> sysParamService.getById(id));
    }

    @PostMapping
    @Operation(summary = "创建")
    public R create(@RequestBody @Validated SysParamEditModel model) {
        return R.ok(() -> sysParamService.create(model));
    }

    @PutMapping
    @Operation(summary = "更新")
    public R update(@RequestBody @Validated SysParamEditModel model) {
        return R.ok(() -> sysParamService.update(model));
    }

    @DeleteMapping("{id}")
    @Operation(summary = "删除")
    public R delete(@PathVariable Long id) {
        return R.ok(() -> sysParamService.delete(id));
    }

}
